#ifndef _UDP_TS_PROTOCOL_
#define _UDP_TS_PROTOCOL_

#include <stdint.h>
#include <string.h>


const char START_PUSH_STREAM 		= '0';//  |(8 bit) 0 |(30 * 8 bit) stream_name  |
const char PUSH_STREAM_DATA  		= '1';//  |(8 bit) 1 |(32bit) sequence | ts-stream......|
const char STOP_PUSH_STREAM			= '2';//  |(8 bit) 2 |

struct ts_dd
{
	uint8_t *data;
	int size;
};


class udpTsProtocolParser
{
public:
	inline static char getPkgType(uint8_t *pkg)
	{
		return (char)pkg[0];
	}
	inline static uint32_t getPkgSequence(uint8_t *pkg)
	{
		return (pkg[4] << 24 | pkg[3] << 16 | pkg[2] << 8 | pkg[1]);
	}
	inline static void getStreamName(uint8_t *pkg,int pkgLen, char *out)
	{
		memcpy(out,pkg+1,pkgLen-1);
		out[pkgLen-1] = '\0';
	}
	inline static ts_dd *getStreamData(uint8_t * pkg,int pkgLen)
	{
		uint8_t * ts_data = new uint8_t[pkgLen - 5];
		ts_dd * ts = new ts_dd();
		ts->data = ts_data;
		ts->size = pkgLen - 5;
		memcpy(ts_data,pkg + 5,pkgLen - 5);
		return ts;
	}
};

#endif
